<template>
    <div ref="chartRef" class="pie-chart"></div>
</template>

<script setup>
import { onBeforeUnmount, onMounted, ref } from 'vue';
import echarts from '@/utils/echart';

const chartRef = ref(null);
let chartObj = null;
const resize = () => {
    chartObj.resize();
};
const init = () => {
    chartObj = echarts.init(chartRef.value);
    const option = {
        tooltip: {
            trigger: 'item'
        },
        series: [
            {
                name: 'Nightingale Chart',
                type: 'pie',
                radius: [20, 70],
                center: ['50%', '50%'],
                roseType: 'area',
                itemStyle: {
                    borderRadius: 2
                },
                data: [
                    { value: 40, name: 'rose 1' },
                    { value: 38, name: 'rose 2' },
                    { value: 32, name: 'rose 3' }
                ]
            }
        ]
    };
    chartObj.setOption(option);
    window.addEventListener('resize', resize);
};
onMounted(() => {
    init();
});
onBeforeUnmount(() => {
    window.addEventListener('resize', resize);
});
</script>
<style lang="less" scoped>
.pie-chart {
    width: 100%;
    height: 100%;
}
</style>
